﻿using System.Data.Objects;
using System.Reflection;
using Equation.Enterprise.Framework.Domain.Data;

namespace Equation.Enterprise.Tests.Framework.Domain.Data
{
    public class TestDbContextBuilder : DbContextBuilder
    {
        public TestDbContextBuilder(string connectionStringName, Assembly[] mappingAssemblies, bool lazyLoadingEnabled = true)
            : base(connectionStringName, mappingAssemblies, lazyLoadingEnabled)
        {
        }

        public bool ExistingDatabase()
        {
            var objectContext = DbCompiledModel.CreateObjectContext<ObjectContext>(this.DbConnection);
            return objectContext.DatabaseExists();
        }

        public void CreateDatabase()
        {
            var objectContext = DbCompiledModel.CreateObjectContext<ObjectContext>(this.DbConnection);
            objectContext.CreateDatabase();
        }

        internal void DropDatabase()
        {
            var objectContext = DbCompiledModel.CreateObjectContext<ObjectContext>(this.DbConnection);
            objectContext.DeleteDatabase();
        }
    }
}
